/*     */ package com.feeyin.radar.sys.service.impl;
/*     */ 
/*     */ import com.feeyin.radar.commons.DateUtils;
/*     */ import com.feeyin.radar.crm.model.UserViewFunPosition;
/*     */ import com.feeyin.radar.sys.dao.FunctionOperateDAO;
/*     */ import com.feeyin.radar.sys.dao.RoleDAO;
/*     */ import com.feeyin.radar.sys.dao.RoleFunctionDAO;
/*     */ import com.feeyin.radar.sys.model.FunctionOperate;
/*     */ import com.feeyin.radar.sys.model.Role;
/*     */ import com.feeyin.radar.sys.model.RoleFunction;
/*     */ import com.feeyin.radar.sys.model.ViewRoleFunction;
/*     */ import com.feeyin.radar.sys.service.RoleService;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ 
/*     */ public class RoleServiceImpl
/*     */   implements RoleService
/*     */ {
/*     */   private RoleDAO roleDAO;
/*     */   private RoleFunctionDAO roleFunctionDAO;
/*     */   private FunctionOperateDAO functionOperateDAO;
/*     */ 
/*     */   public RoleDAO getRoleDAO()
/*     */   {
/*  32 */     return this.roleDAO;
/*     */   }
/*     */ 
/*     */   public void setRoleDAO(RoleDAO roleDAO) {
/*  36 */     this.roleDAO = roleDAO;
/*     */   }
/*     */ 
/*     */   public RoleFunctionDAO getRoleFunctionDAO() {
/*  40 */     return this.roleFunctionDAO;
/*     */   }
/*     */ 
/*     */   public void setRoleFunctionDAO(RoleFunctionDAO roleFunctionDAO) {
/*  44 */     this.roleFunctionDAO = roleFunctionDAO;
/*     */   }
/*     */ 
/*     */   public FunctionOperateDAO getFunctionOperateDAO() {
/*  48 */     return this.functionOperateDAO;
/*     */   }
/*     */ 
/*     */   public void setFunctionOperateDAO(FunctionOperateDAO functionOperateDAO) {
/*  52 */     this.functionOperateDAO = functionOperateDAO;
/*     */   }
/*     */ 
/*     */   public List getRoles() {
/*  56 */     return this.roleDAO.getRoles();
/*     */   }
/*     */ 
/*     */   public Role getRole(Integer id) {
/*  60 */     return this.roleDAO.getRole(id);
/*     */   }
/*     */ 
/*     */   public String getRoleCode() {
/*  64 */     String roleCode = "";
/*  65 */     Integer maxId = this.roleDAO.getRoleMaxId();
/*  66 */     if (maxId != null)
/*  67 */       maxId = Integer.valueOf(maxId.intValue() + 1);
/*     */     else {
/*  69 */       maxId = Integer.valueOf(0);
/*     */     }
/*  71 */     roleCode = maxId.toString();
/*  72 */     if ("0".equals(roleCode))
/*  73 */       roleCode = "001";
/*  74 */     else if (roleCode.length() == 1)
/*  75 */       roleCode = "00" + roleCode;
/*  76 */     else if (roleCode.length() == 2) {
/*  77 */       roleCode = "0" + roleCode;
/*     */     }
/*  79 */     roleCode = DateUtils.getDateByFormat("yyyyMMdd") + roleCode;
/*  80 */     return roleCode;
/*     */   }
/*     */ 
/*     */   public Role getRoleByRoleName(String roleName) {
/*  84 */     return this.roleDAO.getRoleByRoleName(roleName);
/*     */   }
/*     */ 
/*     */   public boolean isRepeatUpdateRole(Role role) {
/*  88 */     if (role == null) return false;
/*     */ 
/*  90 */     Role oldRole = new Role();
/*  91 */     oldRole = this.roleDAO.getRole(role.getId());
/*  92 */     if (oldRole == null) return false;
/*     */ 
/*  94 */     if (!role.getRoleName().equals(oldRole.getRoleName())) {
/*  95 */       Role otherRole = new Role();
/*  96 */       otherRole = this.roleDAO.getRoleByRoleName(role.getRoleName());
/*  97 */       if (otherRole != null) return true;
/*     */     }
/*  99 */     return false;
/*     */   }
/*     */ 
/*     */   public String getFunctionIdsOperateIdsByRoleId(Integer roleId) {
/* 103 */     List roleFunctions = new ArrayList();
/* 104 */     roleFunctions = this.roleFunctionDAO.getRoleFunctionsByRoleId(roleId);
/* 105 */     if (roleFunctions == null) return null;
/*     */ 
/* 107 */     String functionIds = "";
/* 108 */     String operateIds = "";
/* 109 */     for (int i = 0; i < roleFunctions.size(); i++) {
/* 110 */       RoleFunction rfunc = new RoleFunction();
/* 111 */       rfunc = (RoleFunction)roleFunctions.get(i);
/* 112 */       if (i == roleFunctions.size() - 1)
/* 113 */         functionIds = functionIds + rfunc.getFunctionId();
/*     */       else {
/* 115 */         functionIds = functionIds + rfunc.getFunctionId() + ",";
/*     */       }
/*     */ 
/* 118 */       List functionOperates = new ArrayList();
/* 119 */       functionOperates = this.functionOperateDAO.getFunctionOperatesByRoleIdFunctionId(roleId, rfunc.getFunctionId());
/* 120 */       if (functionOperates != null) {
/* 121 */         for (int j = 0; j < functionOperates.size(); j++) {
/* 122 */           FunctionOperate funcOperate = new FunctionOperate();
/* 123 */           funcOperate = (FunctionOperate)functionOperates.get(j);
/* 124 */           operateIds = operateIds + rfunc.getFunctionId() + "#" + funcOperate.getOperateId() + ",";
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/* 129 */     functionIds = functionIds + "##" + operateIds;
/* 130 */     return functionIds;
/*     */   }
/*     */ 
/*     */   public String getViewFunctionIdsByRoleId(Integer roleId) {
/* 134 */     List viewRoleFunctions = new ArrayList();
/* 135 */     viewRoleFunctions = this.roleFunctionDAO.getViewRoleFunctionsByRoleId(roleId);
/* 136 */     if (viewRoleFunctions == null) return null;
/* 137 */     String functionIds = "";
/* 138 */     for (int i = 0; i < viewRoleFunctions.size(); i++) {
/* 139 */       ViewRoleFunction vr = new ViewRoleFunction();
/* 140 */       vr = (ViewRoleFunction)viewRoleFunctions.get(i);
/* 141 */       if (i == viewRoleFunctions.size() - 1)
/* 142 */         functionIds = functionIds + vr.getViewMagId();
/*     */       else {
/* 144 */         functionIds = functionIds + vr.getViewMagId() + ",";
/*     */       }
/*     */     }
/* 147 */     return functionIds;
/*     */   }
/*     */ 
/*     */   public boolean insertRole(Role role, String[] cFunctions, String[] cOperates) {
/* 151 */     if (role == null) return false;
/* 152 */     boolean result = false;
/*     */ 
/* 154 */     result = this.roleDAO.insertRole(role);
/*     */ 
/* 156 */     Role addedRole = new Role();
/* 157 */     addedRole = this.roleDAO.getRoleByRoleCode(role.getRoleCode());
/*     */ 
/* 159 */     if ((cFunctions != null) && (cFunctions.length > 0)) {
/* 160 */       for (int i = 0; i < cFunctions.length; i++) {
/* 161 */         RoleFunction roleFunction = new RoleFunction();
/* 162 */         roleFunction.setRoleId(addedRole.getId());
/* 163 */         roleFunction.setFunctionId(Integer.valueOf(Integer.parseInt(cFunctions[i])));
/* 164 */         this.roleFunctionDAO.insertRoleFunction(roleFunction);
/*     */       }
/*     */     }
/*     */ 
/* 168 */     String[] functionOperateIds = (String[])null;
/* 169 */     String functionId = "";
/* 170 */     String operateId = "";
/* 171 */     if (cOperates != null) {
/* 172 */       for (int i = 0; i < cOperates.length; i++) {
/* 173 */         functionOperateIds = cOperates[i].split("#");
/* 174 */         functionId = functionOperateIds[0];
/* 175 */         operateId = functionOperateIds[1];
/* 176 */         FunctionOperate functionOperate = new FunctionOperate();
/* 177 */         functionOperate.setRoleId(addedRole.getId());
/* 178 */         functionOperate.setFunctionId(Integer.valueOf(Integer.parseInt(functionId)));
/* 179 */         functionOperate.setOperateId(Integer.valueOf(Integer.parseInt(operateId)));
/*     */ 
/* 181 */         this.functionOperateDAO.insertFunctionOperate(functionOperate);
/*     */       }
/*     */     }
/* 184 */     return result;
/*     */   }
/*     */ 
/*     */   public boolean updateRole(Role role) {
/* 188 */     return this.roleDAO.updateRole(role);
/*     */   }
/*     */ 
/*     */   public boolean updateRole(Role role, String[] cFunctions, String[] cOperates) {
/* 192 */     if (role == null) return false;
/* 193 */     boolean result1 = false;
/* 194 */     boolean result2 = false;
/* 195 */     boolean result3 = false;
/*     */ 
/* 197 */     result1 = this.roleFunctionDAO.deleteRoleFunction(role.getId());
/* 198 */     result2 = this.functionOperateDAO.deleteFunctionOperate(role.getId());
/*     */ 
/* 200 */     result3 = this.roleDAO.updateRole(role);
/*     */ 
/* 202 */     if ((cFunctions != null) && (cFunctions.length > 0)) {
/* 203 */       for (int i = 0; i < cFunctions.length; i++) {
/* 204 */         RoleFunction roleFunction = new RoleFunction();
/* 205 */         roleFunction.setRoleId(role.getId());
/* 206 */         roleFunction.setFunctionId(Integer.valueOf(Integer.parseInt(cFunctions[i])));
/* 207 */         this.roleFunctionDAO.insertRoleFunction(roleFunction);
/*     */       }
/*     */     }
/*     */ 
/* 211 */     String[] functionOperateIds = (String[])null;
/* 212 */     String functionId = "";
/* 213 */     String operateId = "";
/* 214 */     if (cOperates != null) {
/* 215 */       for (int i = 0; i < cOperates.length; i++) {
/* 216 */         functionOperateIds = cOperates[i].split("#");
/* 217 */         functionId = functionOperateIds[0];
/* 218 */         operateId = functionOperateIds[1];
/* 219 */         FunctionOperate functionOperate = new FunctionOperate();
/* 220 */         functionOperate.setRoleId(role.getId());
/* 221 */         functionOperate.setFunctionId(Integer.valueOf(Integer.parseInt(functionId)));
/* 222 */         functionOperate.setOperateId(Integer.valueOf(Integer.parseInt(operateId)));
/*     */ 
/* 224 */         this.functionOperateDAO.insertFunctionOperate(functionOperate);
/*     */       }
/*     */     }
/* 227 */     return (result1) && (result2) && (result3);
/*     */   }
/*     */ 
/*     */   public boolean insertRole(Role role, String[] functions) {
/* 231 */     if (role == null) return false;
/* 232 */     boolean result1 = false;
/* 233 */     boolean result3 = false;
/* 234 */     result1 = this.roleFunctionDAO.deleteViewRoleFunction(role.getId());
/* 235 */     result3 = this.roleDAO.updateRole(role);
/* 236 */     if ((functions != null) && (functions.length > 0)) {
/* 237 */       for (int i = 0; i < functions.length; i++) {
/* 238 */         ViewRoleFunction viewRoleFunction = new ViewRoleFunction();
/* 239 */         viewRoleFunction.setRoleId(role.getId());
/* 240 */         viewRoleFunction.setViewMagId(Integer.valueOf(Integer.parseInt(functions[i])));
/* 241 */         this.roleFunctionDAO.insertViewRoleFunction(viewRoleFunction);
/*     */       }
/*     */     }
/* 244 */     return (result1) && (result3);
/*     */   }
/*     */ 
/*     */   public boolean updateRole(Role role, String[] functions) {
/* 248 */     if (role == null) return false;
/* 249 */     boolean result1 = false;
/* 250 */     boolean result3 = false;
/* 251 */     result1 = this.roleFunctionDAO.deleteViewRoleFunction(role.getId());
/* 252 */     result3 = this.roleDAO.updateRole(role);
/* 253 */     if ((functions != null) && (functions.length > 0)) {
/* 254 */       for (int i = 0; i < functions.length; i++) {
/* 255 */         ViewRoleFunction viewRoleFunction = new ViewRoleFunction();
/* 256 */         viewRoleFunction.setRoleId(role.getId());
/* 257 */         viewRoleFunction.setViewMagId(Integer.valueOf(Integer.parseInt(functions[i])));
/* 258 */         this.roleFunctionDAO.insertViewRoleFunction(viewRoleFunction);
/*     */       }
/*     */     }
/* 261 */     return (result1) && (result3);
/*     */   }
/*     */ 
/*     */   public boolean deleteRole(Integer id) {
/* 265 */     return this.roleDAO.deleteRole(id);
/*     */   }
/*     */ 
/*     */   public boolean deleteRoles(String[] ids) {
/* 269 */     if ((ids == null) || (ids.length <= 0)) return false;
/* 270 */     for (int i = 0; i < ids.length; i++) {
/* 271 */       this.roleDAO.deleteRole(Integer.valueOf(Integer.parseInt(ids[i])));
/*     */     }
/* 273 */     return true;
/*     */   }
/*     */ 
/*     */   public boolean addUserViewFunPosition(Integer userId, List list) {
/* 277 */     if (userId == null) return false;
/* 278 */     boolean result1 = false;
/* 279 */     result1 = this.roleFunctionDAO.deleteUserViewFunPositionByUserId(userId);
/* 280 */     if ((list != null) && (list.size() > 0)) {
/* 281 */       for (int i = 0; i < list.size(); i++) {
/* 282 */         this.roleFunctionDAO.insertUserViewFunPosition((UserViewFunPosition)list.get(i));
/*     */       }
/*     */     }
/* 285 */     return result1;
/*     */   }
/*     */ 
/*     */   public List getUserViewFunPosition(Integer userId) {
/* 289 */     return this.roleFunctionDAO.getUserViewFunPositionByUserId(userId);
/*     */   }
/*     */ 
/*     */   public List getLeftUserViewFunPositionByUserId(Integer userId) {
/* 293 */     return this.roleFunctionDAO.getLeftUserViewFunPositionByUserId(userId);
/*     */   }
/*     */ 
/*     */   public List getRightUserViewFunPositionByUserId(Integer userId) {
/* 297 */     return this.roleFunctionDAO.getRightUserViewFunPositionByUserId(userId);
/*     */   }
/*     */   public List getViewRoleFunctionsByUserId(Integer userid) {
/* 300 */     return this.roleFunctionDAO.getViewRoleFunctionsByUserId(userid);
/*     */   }
/*     */ }

/* Location:           C:\Users\e547415\MyProject\rone\WEB-INF\classes\
 * Qualified Name:     com.feeyin.radar.sys.service.impl.RoleServiceImpl
 * JD-Core Version:    0.6.0
 */